//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace OpenLS.Spreadsheet.UI
{
    class MultiEqualConverter: IMultiValueConverter
    {
        #region IMultiValueConverter Members

        object IMultiValueConverter.Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            object first = values[0];
            foreach (object o in values)
                if (o != first)
                    return Convert(false, targetType);
            return Convert(true, targetType);
        }

        private static object Convert(bool p, Type targetType)
        {
            if (targetType == typeof(object))
                return p;
            if (targetType == typeof(bool))
                return p;
            if (targetType == typeof(Visibility))
                if (p)
                    return Visibility.Visible;
            return Visibility.Hidden;
        }

        object[] IMultiValueConverter.ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}
